﻿package samples
{
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import marcel.debug.*;
	import marcel.display.View;
	import marcel.events.*;
	import marcel.external.FileLoader;
	import marcel.external.FileType;
	
	
	public class FileLoaderSample extends View
	{
		public function FileLoaderSample()
		{
			// create instance to load an image
			var fileLoader:FileLoader = new FileLoader(FileType.IMAGE);
			
			// listening to progress and complete events
			fileLoader.addEventListener(FileLoaderEvent.PROGRESS, onLoadProgress);
			fileLoader.addEventListener(FileLoaderEvent.COMPLETE, onLoadComplete);
			
			// start loading
			fileLoader.load("http://www.google.fr/intl/en_com/images/srpr/logo1w.png");
		}
		
		public function onLoadComplete(evt:FileLoaderEvent):void
		{
			// load complete, get the target fileloader
			var fl:FileLoader = evt.fileLoader;
			
			// trace loaded file URI
			debug(fl.fileUri);
			
			// display loaded image
			addChild(evt.content);
		}
		
		public function onLoadProgress(evt:FileLoaderEvent):void
		{
			// trace loading progress
			debug(evt.fileLoader.fileUri + " " + evt.percent);
		}
	}
}